package cn.pn.project.mapper.user;

import cn.pn.project.pojo.base.Coupon;
import cn.pn.project.pojo.user.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
@Component
@Mapper
public interface UserCouponDao {
    /**
     *  根据状态和用户id查询优惠券id
     * @param status   状态
     * @return  优惠券id集合
     */
    @Select("SELECT * FROM usercoupon WHERE status=#{status} AND userId=#{userId};")
    List<Usercoupon> findByStatus(@Param("status") Integer status, @Param("userId") Integer userId) throws Exception;

    /**
     * 积分抽奖添加用户优惠券
     * @param usercoupon
     * @return
     */
    @Insert("INSERT INTO `pn_user`.`usercoupon` (\n" +
            "  `userId`,\n" +
            "  `couponId`,\n" +
            "  `loseDate`,\n" +
            "  `getDate`\n" +
            ")\n" +
            "VALUES\n" +
            "  (\n" +
            "    #{userId},\n" +
            "    #{couponId},\n" +
            "    #{loseDate},\n" +
            "    #{getDate}\n" +
            "  );")
    Integer AddUsercoupon(Usercoupon usercoupon) throws Exception;

    /**
     * 免费领取添加用户优惠券
     * @param usercoupon
     * @return
     */
    @Insert("INSERT INTO `pn_user`.`usercoupon` (\n" +
            "  `userId`,\n" +
            "  `couponId`,\n" +
            "  `loseDate`,\n" +
            "  `getDate`\n" +
            ")\n" +
            "VALUES\n" +
            "  (\n" +
            "    #{userId},\n" +
            "    #{couponId},\n" +
            "    #{loseDate},\n" +
            "    #{getDate}\n" +
            "  );")
    Integer AddUsercouponmf(Usercoupon usercoupon) throws Exception;

    /**
     * 根据用户优惠券id删除用户优惠券
     * @param userCouponId
     * @return
     * @throws Exception
     */
    @Delete("DELETE\n" +
            "FROM\n" +
            "  `pn_user`.`usercoupon`\n" +
            "WHERE `userCouponId` = #{UserCouponId};\n")
    Integer DelUserCoupon(Integer userCouponId) throws  Exception;
}
